package fr.emse.tatiana.replayable;

import java.io.File;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
import fr.emse.tatiana.corpus.Corpus;

public class ReplayableInputFactory implements IElementFactory {

    /**
     * Factory id. The workbench plug-in registers a factory by this name
     * with the "org.eclipse.ui.elementFactories" extension point.
     */
    private static final String ID_FACTORY = "fr.emse.tatiana.FilterInputFactory"; //$NON-NLS-1$

    /**
     * Tag for the IFile.fullPath of the file resource.
     */
    private static final String TAG_PATH = "path"; //$NON-NLS-1$


    /**
     * Creates a new factory.
     */
    public ReplayableInputFactory() {
    }

    /* (non-Javadoc)
     * Method declared on IElementFactory.
     */
    public IAdaptable createElement(IMemento memento) {
        // Get the file name.
        String fileName = memento.getString(TAG_PATH);
        if (fileName == null) {
			return null;
		}


        // TODO z later fix me (store correct values in memento and use them to recreate corpus)
		return new ReplayableInput(fileName, new Corpus(null));

    }

    /**
     * Returns the element factory id for this class.
     * 
     * @return the element factory id
     */
    public static String getFactoryId() {
        return ID_FACTORY;
    }

    /**
     * Saves the state of the given file editor input into the given memento.
     *
     * @param memento the storage area for element state
     * @param input the file editor input
     */
    public static void saveState(IMemento memento, ReplayableInput input) {
        File file = input.getFile();
        Corpus corpus = input.getCorpus();
        memento.putString(TAG_PATH, file.getAbsolutePath());
    }


}
